package com.ly.designpatten.factory;

import com.ly.designpatten.factory.common.Pizza;

/**
 * @Classname SimpleFactory
 * @Description TODO
 * @Date 2020/10/7 11:33
 * @Author 冷心影翼
 */
public class SimpleFactory {

	public Pizza createPizza(String type) {
		Pizza pizza = null;
		if(type == "A") {
			pizza = new PizzaA();
			pizza.pre();
		}else if(type == "B") {
			pizza = new PizzaB();
		}
		if(pizza != null) {
			pizza.pre();
			pizza.bake();
			pizza.cut();
			pizza.box();
		}
		return pizza;
	}

	public static void main(String[] args) {
		SimpleFactory simpleFactory = new SimpleFactory();
		Pizza pizzaA = simpleFactory.createPizza("A");
		Pizza pizzaB = simpleFactory.createPizza("B");
	}
}


class PizzaA extends Pizza {

	public PizzaA() {
		super("pizzA");
	}
	@Override
	public void pre() {

		System.out.println(name+"正在准备");
	}
}


class PizzaB extends Pizza {

	public PizzaB() {
		super("pizzB");
	}
	@Override
	public void pre() {

		System.out.println(name+"正在准备");
	}
}


